#pragma once
#pragma once

#include <string.h>
#include <iostream>
#include <assert.h>
using std::cin;
using std::cout;
using std::endl;

namespace BLZ
{
	class string
	{
	private:
		char* _str;
		size_t _size;
		size_t _capa;
	public:
		typedef char* iterator;
		typedef const char* const_iterator;
		static const size_t npos;

		string(const char* str = "")
			:_size(strlen(str))
		{
			_capa = _size;
			_str = new char[_capa + 1];
			memcpy(_str, str, _size + 1);
		}
		string(const string& str)
		{
			_capa = str._capa;
			_size = str._size;
			_str = new char[_capa + 1];
			memcpy(_str, str._str, _size + 1);
		}
		~string()
		{
			delete[] _str;
			_str = nullptr;
			_capa = 0;
			_size = 0;
		}
		const char* c_str() const;
		void clear();
		char& operator[] (size_t i);
		const char& operator[](size_t i) const;
		iterator begin();
		iterator end();
		const_iterator begin() const;
		const_iterator end() const;
		size_t size() const;
		void reserve(size_t n);
		void push_back(char c);
		void append(const char* s);
		string& operator+=(char c);
		string& operator+=(const char* s);
		string& insert(size_t pos, char c);
		string& insert(size_t pos, const char* s);
		string& erase(size_t pos = 0, size_t len = npos);
		size_t find(char c, size_t pos = 0) const;
		size_t find(const char* s, size_t pos = 0) const;
		string substr(size_t pos = 0, size_t len = npos) const;
		string& operator=(const string& str);
		bool operator<(const string& str) const;
		bool operator>(const string& str) const;
		bool operator<=(const string& str) const;
		bool operator>=(const string& str) const;
		bool operator==(const string& str) const;
		bool operator!=(const string& str) const;
		void swap(string& str);
	};
	std::ostream& operator<<(std::ostream& os, const BLZ::string& str);
	std::istream& operator>>(std::istream& is, BLZ::string& str);
}